﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.NetworkHelpers;

namespace A2DFramework.UniqueIdGeneratorService
{
    public static class UniqueIdGenerator
    {
        static UniqueIdGenerator()
        {
            string ipAddress = IPHelper.GetLocalIPv4();
            ip = UniqueIdGeneratorHelper.IP2Long(ipAddress);
        }

        private static long ip = 0;
        public static decimal Next()
        {
            return decimal.Parse(DateTime.Now.ToString("yyyyMMddHHmmssff") + ip.ToString() + GetSequence().ToString());
        }

        private static int curSeq = 1;
        private static object o = 1;
        private static int GetSequence()
        {
            lock (o)
            {
                if (curSeq > 999)
                    curSeq = 1;
                return curSeq++;
            }
        }
    }
}
